<link rel="stylesheet" href="<?php echo STATIC_URL.'/backend/css/notice.css'?>" />
<?php $this->load->view('templates/backend/lib'); ?>
<?php $result = json_decode($noidung);?>
<style>
    .fone_num_cls{margin-left:32px;}
</style>
<script>
function sending(){
    var phone       = $('#phone option:selected').text();   
    var message     = <?php echo ($result)?json_encode($result):'';?>;
    
    if ( $("#showCr").is(':checked') ) {
        var str1     = $("#airline_fake").text().trim().toUpperCase() +" \n"+$("#paxname_fake").text().trim().toUpperCase()+" \n"+$("#message_fake").text().trim().toUpperCase()+" \n"+$("#total").text().trim().toUpperCase()+" \n";
        var showCr   = '1';
    } else {
        var str1     = $("#airline_fake").text().trim().toUpperCase() +" \n"+$("#paxname_fake").text().trim().toUpperCase()+" \n"+$("#message_fake").text().trim().toUpperCase()+" \n";
        var showCr   = '0';
    }
    
    var str3     = '';
    if($("#hanhly").val()!=""){
        str3    =   str1+'HANH LY: '+$("#hanhly").val().trim().toUpperCase()+"\n";
    } else {
        str3    =   str1;
    }

    var str4    =  str3 + '\n\nBẠN CHẮC CHẮN MUỐN GỞI NỘI DUNG TIN NHẮN NÀY CHO SDT '+phone;
    if (!confirm(str4)) {
        return false;
    }
    
    $('#submit').attr('disabled','disabled');
    $('#cancel').attr('disabled','disabled');
    $("#success").html("<img src='<?php echo STATIC_URL;?>/backend/images/icon/loading-2.gif' /> <br/> Vui lòng chờ");
    setTimeout(function () {
        $.ajax(
            {
                url : '/auth/bookhistory/sendsms',
                type: "POST",
                data : { phone: phone, message:message,hanhly:$("#hanhly").val(),showCr:showCr},
                cache: true,
                beforeSend: function(){
                    $("#success").html("<img src='<?php echo STATIC_URL;?>/backend/images/icon/loading-2.gif' /> <br/> Đang xử lí");
                },
                success:function(data)
                {
                    setTimeout(function () {
                        if(data==0){
                            $("#success").html("Gởi tin nhắn thành công!");
                            setTimeout(function () {
                                closeFancy();
                            },2000);
                            
                        } else {
                            $('#submit').removeAttr('disabled','disabled');
                            $('#cancel').removeAttr('disabled','disabled');
                            $("#success").html("Gởi tin nhắn thất bại!");
                        }
                    },2000);
                },
                error: function() 
                {
                    $("#success").html("Gởi tin nhắn thất bại!");
                }
            });
     },2000);
}
function closeFancy(){
    parent.jQuery.fancybox.close();
}
</script>

<div id="container2">
    <h3 id="nav2" class="logo">
        <a id="logo">THÔNG TIN GỞI TIN NHẮN</a>
    </h3>
    <div id="wufoo-mz9i3ib0wkzqls">
        <?php
            if($checker){
        ?>
                <div style="padding-left:10px">
                    <?php 
                    echo form_label($this->lang->line('customer'), 'customer',array('style'=>'padding-right:50px;')).$customer;
                    echo '<br/>';
                    echo form_label($this->lang->line('phone'), 'phone',array('style'=>'padding-right:40px;'));
                    echo form_dropdown('phone', $phone, 1,'id="phone"');
                    echo form_error('phone');
                    echo '<br/>';
                    echo form_label($this->lang->line('trunk'), 'trunk',array('style'=>'padding-right:55px;')).form_input(array('name' => 'hanhly', 'id' => 'hanhly', 'value' => '','placeholder'=>$this->lang->line('trunk'),'class' => 'fone_num_cls'));
                    echo '<br/>';
                    echo form_label($this->lang->line('showCr'), 'showCr',array('style'=>'padding-right:47px;')).form_checkbox(array('id'=>'showCr','checked'=>TRUE,'style'=>'vertical-align: top;'));
                    ?>
                    <br/><br/>
                    <div id="content-sms">
                            <p>NỘI DUNG TIN NHẮN:</p>
                            <span id="airline"><?php echo ($result->airline)?$result->airline."<br/>":'';?><?php echo ($result->pnr)?'CODE: '.$result->pnr." <br/>":'';?></span>
                            <span id="airline_fake" style="display:none;"><?php echo ($result->airline)?$result->airline." \n":'';?><?php echo ($result->pnr)?'CODE: '.$result->pnr." \n":'';?></span>
                            <span id="paxname"><?php echo ($result->paxname)?implode(" <br/>", $result->paxname):'';  ?></span> <br/>
                            <span id="paxname_fake" style="display:none;"><?php echo ($result->paxname)?implode(" \n", $result->paxname):'';  ?></span> 
                            <span id="message"><?php echo ($result->message)?implode(" <br/>",$result->message):'';  ?></span> <br/> 
                            <span id="message_fake" style="display:none;"><?php echo ($result->message)?implode(" \n",$result->message):'';  ?></span> 
                            <span id="total"><?php echo ($result->total)?'GIA: '.$result->total:'';  ?></span> <br/>
                        <span id="hanhli-hidden"></span>
                    </div>
                </div>
                <div class="top-button">
                        <?php echo form_button(array('id' => 'submit', 'name' => 'submit', 'content' => $this->lang->line('continue'),'class' => 'btn btn-primary','onclick'=>'sending()')); ?>
                        <?php echo form_button(array('id' => 'cancel','content' => $this->lang->line('close'),'class' => 'btn','onclick'=>'closeFancy()')); ?>
                </div>
                <div id="success"></div>
        <?php
            } else {
                echo '<p style="text-align: center;">BOOKING NÀY KHÔNG PHẢI DO BẠN ĐẶT! <br/>BẠN KHÔNG THỂ GỞI!</p>';
                echo '<div class="top-button">'.form_button(array('id' => 'cancel','content' => $this->lang->line('close'),'class' => 'btn','onclick'=>'closeFancy()')).'</div>';
            }
        ?>
    </div>
</div>
